
#ifndef _TTG_PIPELINE_PIPELINEINFO_
#define _TTG_PIPELINE_PIPELINEINFO_
#include "Common/Definitions.h"

#ifdef TTG_PL_VISUALIZER

#include <vector>
#include <list>
#include "Common/Errors.h"
#include "Runtime.Low/Threads.h"
#include "Runtime.Low/Services.h"
#include "Runtime.Low/Utils.h"

#include "../Nodes/NavigatorNode.h"

namespace ttg_internal
{
	namespace pipeline
	{
		//Contains formatted info about pipeline.
		class PipelineInfo :public ttg::structures::NamedObject,
							public ttg::services::Event
		{
			private:
				bool is_independent;
				ttg::utils::ParameterSet *nodes_filter;
				ttg::utils::ParameterSet *sub_pipelines_filter;
				//Performers
				std::vector<PerformerInfo *> performers;
				//Nodes
				double starttime;					 //Start time
				double frametime;					 //Frame rendering time
				double summedtime;					 //Useful time
				threads::CriticalSection *nodes_cs;  //Section for synchronization with pipeline
				std::vector<NodeInfo *> nodes;
				PipelineInfo(); //version for deserialization (create()).
			public:
				//Creates Pipeline info (by first node).
				PipelineInfo(const char *name,
							 std::vector<ttg_internal::pipeline::NavigatorNode *> &nodes,
							 threads::CriticalSection *nodes_cs);
				//Returns filter for this pipeline.
				inline ttg::utils::ParameterSet *getFilter()
				{ return nodes_filter; }
				//Returns filter for nodes.
				inline ttg::utils::ParameterSet *getNodesFilter()
				{ return nodes_filter; }
				//Returns filter for sub-pipelines.
				inline ttg::utils::ParameterSet *getSubPipelinesFilter()
				{ return sub_pipelines_filter; }
				//Copies values from nodes to local memory.
				//Must be called by pipeline (between iterations).
				void update(double starttime, double frametime,
							const std::vector<PerformerInfo *> &performers);
				//Optional. Locks nodes. After it information cannot be changed change.
				//Must be call only by diffrent thread.
				inline void lock()
				{ nodes_cs->enter(); }
				//Optional. Allows PipeLine to update info.
				//Must be call only by diffrent thread.
				inline void unLock()
				{ nodes_cs->leave(); }
				//Returns info about performers.
				inline std::vector<PerformerInfo *> &getPerformers()
				{ return performers; }
				//Returns all nodes.
				inline std::vector<NodeInfo *> &getNodes()
				{ return nodes; }
				//Returns time of start.
				inline double getStartTime() const
				{ return starttime; }
				//Returns frame rendering time.
				inline double getFrameTime() const
				{ return frametime; }
				//Returns useful time.
				inline double getSummedTime() const
				{ return summedtime; }
				~PipelineInfo();
				//Creates PipelineInfo according to xml ("Pipeline" section is expected).
				static PipelineInfo *create(ttg::extras::XMLTree &xml);
				//Creates new section "Pipeline" ans stores info.
				static void store(ttg::extras::XMLTree &xml, PipelineInfo *val);
		};
	}
}

#endif

#endif
